package com.jbm.jbmsupplier.activity.register.view

import android.support.design.widget.TextInputLayout
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.TextView
import com.jbm.enterapplication.R
import com.jbm.enterapplication.activity.MainActivity
import com.jbm.enterapplication.utlisclass.ExitActivity
import com.jbm.jbmsupplier.activity.register.presenter.Register_Present_Con
import kotlinx.android.synthetic.main.activity_register__construction.*
import kotlinx.android.synthetic.main.lz_titlehurdle.*

class Register_Construction : MainActivity(), View.OnClickListener, Register_Construction_Massages {
    override fun finlis() {
        finish()
    }

    override fun getValidateCodes(): TextView {
        return register_butt_hqyzm_con
    }

    override fun getView(): Int {
        return R.layout.activity_register__construction
    }

    override fun getinit() {
        ExitActivity.getInstanst().addActivity(this)
        register_butt_hqyzm_con.setOnClickListener(this)
        register_manage_button_con.setOnClickListener(this)
        register_present_con = Register_Present_Con(this,this);
        tiet_photo_con.addTextChangedListener( MyWatcher(tiet_photo_con))
        tiet_yzm_con.addTextChangedListener( MyWatcher(tiet_yzm_con))
        tiet_password_con.addTextChangedListener( MyWatcher(tiet_password_con))
        teleft.setOnClickListener(this)
        tetitle.text="注册"
    }

    override fun getPhoneErr(): TextInputLayout {
        return til_photo_con
    }

    override fun getValidateCodeErr(): TextInputLayout {
        return til_yzm_con    }

    override fun getPasWordErr(): TextInputLayout {
        return til_password_con    }

    /**setContentView()
     *  +
     * initIalizeView()
     * 在AllActivityApp()类中
     *
     */
    var register_present_con: Register_Present_Con? = null

    override fun getPhone(): String {//获取手机号
            return tiet_photo_con.editableText.toString()



    }

    override fun getValidateCode(): String {//获取验证码


            return tiet_yzm_con.editableText.toString()



    }

    override fun getPasWord(): String {//获取密码
            return tiet_password_con.editableText.toString()


    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.register_manage_button_con -> {//注册管理员
                register_present_con?.getRegisterUserMassage(this)
            }
            R.id.register_butt_hqyzm_con -> {//获取验证码
                register_present_con?.getValidateCode()
            }
            R.id.teleft->{
                finish()
            }



        }
    }
    inner  internal class MyWatcher : TextWatcher {
        var view:View?=null
        constructor(view: View?) {
            this.view = view
        }
        override fun afterTextChanged(s: Editable?) {
            when(view?.id){
                R.id.tiet_photo_con ->{
                    if (s!!.length>=11){
                        til_photo_con.isErrorEnabled=false
                    }else if (!s.toString().equals(""))
                        til_photo_con.isErrorEnabled=false
                }
                R.id.tiet_yzm_con ->{
                    if (!s.toString().equals(""))
                        til_yzm_con.isErrorEnabled=false
                }
                R.id.tiet_password_con ->{
                    if (!s.toString().equals(""))
                        til_password_con.isErrorEnabled=false
                }
            }

        }

        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

        }

        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

        }

    }

}
